package com.situ.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.common.ServerResponse;
import com.situ.crm.entity.Role;
import com.situ.crm.entity.RolePermission;
import com.situ.crm.service.IRoleService;

@Controller
@RequestMapping(value="/role")
public class RoleController {
	@Autowired
	private IRoleService roleService;
	
	@RequestMapping(value="/getRolePage")
	public String getRolePage() {
		return "role/role_list";
	}
	
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer limit,Integer page,Role role) {
		ServerResponse serverResponse = roleService.pageList(limit,page,role);
		return serverResponse;
	}
	
	//添加页面
	@RequestMapping(value="/getAddPage")
	public String getAddPage() {
		return "role/role_insert";
	}
	
	//添加功能、有权限
	@RequestMapping(value="/insert")
	@ResponseBody
	public ServerResponse insert(Role role,String permissions) {
		return roleService.insert(role,permissions);
	}
	
	//删除
	@RequestMapping(value="/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return roleService.deleteById(id);
	}
	
	//批量删除
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return roleService.deleteAll(ids);
	}
	
	//修改页面
	@RequestMapping(value="/getUpdatePage")
	public String getUpdatePage() {
		return "role/role_update";
	}
	
	//修改页面展示的数据
	@RequestMapping(value="/selectRoleAndPermission")
	@ResponseBody
	public ServerResponse selectRoleAndPermission(Integer roleId) {
		System.err.println(roleId);
		System.err.println((roleService.selectRoleAndPermission(roleId)).getData());
		return roleService.selectRoleAndPermission(roleId);
	}
	
	//修改功能
	@RequestMapping(value="/update")
	@ResponseBody
	public ServerResponse update(Role role,String permissions) {
		return roleService.update(role,permissions);
	}
	
	//用户添加页面查询所有的角色
	@RequestMapping(value="/selectAllRole")
	@ResponseBody
	public ServerResponse selectAllRole() {
		return roleService.selectAllRole();
	}
	
}
